#ifndef THINK_TRAITS_CONTROLLER_JUMP_H
#define THINK_TRAITS_CONTROLLER_JUMP_H

static char* traits_controller_jump =
	"\n"
	"/**\n"
	" * 用法：\n"
	" * load_trait(\'controller/Jump\');\n"
	" * class index\n"
	" * {\n"
	" *     use \\traits\\controller\\Jump;\n"
	" *     public function index(){\n"
	" *         $this->error();\n"
	" *         $this->redirect();\n"
	" *     }\n"
	" * }\n"
	" */\n"
	"namespace traits\\controller;\n"
	"\n"
	"use think\\Config;\n"
	"use think\\exception\\HttpResponseException;\n"
	"use think\\Request;\n"
	"use think\\Response;\n"
	"use think\\response\\Redirect;\n"
	"use think\\Url;\n"
	"use think\\View as ViewTemplate;\n"
	"\n"
	"trait Jump\n"
	"{\n"
	"    /**\n"
	"     * 操作成功跳转的快捷方法\n"
	"     * @access protected\n"
	"     * @param mixed  $msg    提示信息\n"
	"     * @param string $url    跳转的 URL 地址\n"
	"     * @param mixed  $data   返回的数据\n"
	"     * @param int    $wait   跳转等待时间\n"
	"     * @param array  $header 发送的 Header 信息\n"
	"     * @return void\n"
	"     * @throws HttpResponseException\n"
	"     */\n"
	"    protected function success($msg = \'\', $url = null, $data = \'\', $wait = 3, array $header = [])\n"
	"    {\n"
	"        if (is_null($url) && !is_null(Request::instance()->server(\'HTTP_REFERER\'))) {\n"
	"            $url = Request::instance()->server(\'HTTP_REFERER\');\n"
	"        } elseif (\'\' !== $url && !strpos($url, \'://\') && 0 !== strpos($url, \'/\')) {\n"
	"            $url = Url::build($url);\n"
	"        }\n"
	"\n"
	"        $type = $this->getResponseType();\n"
	"        $result = [\n"
	"            \'code\' => 1,\n"
	"            \'msg\'  => $msg,\n"
	"            \'data\' => $data,\n"
	"            \'url\'  => $url,\n"
	"            \'wait\' => $wait,\n"
	"        ];\n"
	"\n"
	"        if (\'html\' == strtolower($type)) {\n"
	"            $template = Config::get(\'template\');\n"
	"            $view = Config::get(\'view_replace_str\');\n"
	"\n"
	"            $result = ViewTemplate::instance($template, $view)\n"
	"                ->fetch(Config::get(\'dispatch_success_tmpl\'), $result);\n"
	"        }\n"
	"\n"
	"        $response = Response::create($result, $type)->header($header);\n"
	"\n"
	"        throw new HttpResponseException($response);\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 操作错误跳转的快捷方法\n"
	"     * @access protected\n"
	"     * @param mixed  $msg    提示信息\n"
	"     * @param string $url    跳转的 URL 地址\n"
	"     * @param mixed  $data   返回的数据\n"
	"     * @param int    $wait   跳转等待时间\n"
	"     * @param array  $header 发送的 Header 信息\n"
	"     * @return void\n"
	"     * @throws HttpResponseException\n"
	"     */\n"
	"    protected function error($msg = \'\', $url = null, $data = \'\', $wait = 3, array $header = [])\n"
	"    {\n"
	"        if (is_null($url)) {\n"
	"            $url = Request::instance()->isAjax() ? \'\' : \'javascript:history.back(-1);\';\n"
	"        } elseif (\'\' !== $url && !strpos($url, \'://\') && 0 !== strpos($url, \'/\')) {\n"
	"            $url = Url::build($url);\n"
	"        }\n"
	"\n"
	"        $type = $this->getResponseType();\n"
	"        $result = [\n"
	"            \'code\' => 0,\n"
	"            \'msg\'  => $msg,\n"
	"            \'data\' => $data,\n"
	"            \'url\'  => $url,\n"
	"            \'wait\' => $wait,\n"
	"        ];\n"
	"\n"
	"        if (\'html\' == strtolower($type)) {\n"
	"            $template = Config::get(\'template\');\n"
	"            $view = Config::get(\'view_replace_str\');\n"
	"\n"
	"            $result = ViewTemplate::instance($template, $view)\n"
	"                ->fetch(Config::get(\'dispatch_error_tmpl\'), $result);\n"
	"        }\n"
	"\n"
	"        $response = Response::create($result, $type)->header($header);\n"
	"\n"
	"        throw new HttpResponseException($response);\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 返回封装后的 API 数据到客户端\n"
	"     * @access protected\n"
	"     * @param mixed  $data   要返回的数据\n"
	"     * @param int    $code   返回的 code\n"
	"     * @param mixed  $msg    提示信息\n"
	"     * @param string $type   返回数据格式\n"
	"     * @param array  $header 发送的 Header 信息\n"
	"     * @return void\n"
	"     * @throws HttpResponseException\n"
	"     */\n"
	"    protected function result($data, $code = 0, $msg = \'\', $type = \'\', array $header = [])\n"
	"    {\n"
	"        $result = [\n"
	"            \'code\' => $code,\n"
	"            \'msg\'  => $msg,\n"
	"            \'time\' => Request::instance()->server(\'REQUEST_TIME\'),\n"
	"            \'data\' => $data,\n"
	"        ];\n"
	"        $type     = $type ?: $this->getResponseType();\n"
	"        $response = Response::create($result, $type)->header($header);\n"
	"\n"
	"        throw new HttpResponseException($response);\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * URL 重定向\n"
	"     * @access protected\n"
	"     * @param string    $url    跳转的 URL 表达式\n"
	"     * @param array|int $params 其它 URL 参数\n"
	"     * @param int       $code   http code\n"
	"     * @param array     $with   隐式传参\n"
	"     * @return void\n"
	"     * @throws HttpResponseException\n"
	"     */\n"
	"    protected function redirect($url, $params = [], $code = 302, $with = [])\n"
	"    {\n"
	"        if (is_integer($params)) {\n"
	"            $code   = $params;\n"
	"            $params = [];\n"
	"        }\n"
	"\n"
	"        $response = new Redirect($url);\n"
	"        $response->code($code)->params($params)->with($with);\n"
	"\n"
	"        throw new HttpResponseException($response);\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 获取当前的 response 输出类型\n"
	"     * @access protected\n"
	"     * @return string\n"
	"     */\n"
	"    protected function getResponseType()\n"
	"    {\n"
	"        return Request::instance()->isAjax()\n"
	"            ? Config::get(\'default_ajax_return\')\n"
	"            : Config::get(\'default_return_type\');\n"
	"    }\n"
	"}\n"
	"\n"
;
#endif